package com.code;

import java.io.IOException;
import java.io.PrintWriter;
import com.utils.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.utils.QRCodeUtil;

/**
 * Servlet implementation class QrCodeServlet
 */
@WebServlet("/QrCodeServlet")
public class QrCodeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public QrCodeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//doGet(request, response);
		request.setCharacterEncoding("utf-8");  
		//response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String name=request.getParameter("name");
		String add=request.getParameter("add");
		String work=request.getParameter("work");
		String bumen=request.getParameter("bumen");
		String tel=request.getParameter("tel");
		String num=request.getParameter("num");
		String mail=request.getParameter("mail");
		String state=request.getParameter("state");
		System.out.print(tel);
		String text= "BEGIN:VCARD \r\n" + 
        		"VERSION:4.0 \r\n" + 
        		"PRODID:ez-vcard 0.9.11 \r\n" + 
        		"N:;"+name+";;; \r\n" + 
        		"ADR;TYPE=部 门;TZ=UTC+8:;;"+bumen+";;;; \r\n" +
        		"ADR;TYPE=地 址;TZ=UTC+8:;;"+add+";;;; \r\n" + 
        		"EMAIL;TYPE=邮 箱;PREF=1: "+mail+" \r\n" + 
        		"TEL;TYPE=手 机:"+tel+" \r\n" + 
        		"TEL;TYPE=固 话:"+num+" \r\n" + 
        		"ORG:"+work+" \r\n" + 
        		"END:VCARD ";
		PrintWriter out = response.getWriter();
		try {
			//QRCodeUtil.encode("text", "d:/imgs/timg1.jpg", "d:/imgs", true);
			String picSrc=QRCodeUtil.encode(text, "e:/Codeimgs/timg1.jpg", "e:/Codeimgs/", true);
			out.print(picSrc);
			out.flush();
			out.close();
		}catch(Exception e) {
			e.printStackTrace();
		}
	}

}
